<?php 
/**
 *   Joomdiet - components/views/recipeinfotable/tmpl/default.php
 *   Author: Juan Dapena Paz (juan@bittingbits.com)
 *   Copyright (C) 2010 Bitting Bits S.L.
 *
 *   This program is free software: you can redistribute it and/or modify
 *   it under the terms of the GNU General Public License as published by
 *   the Free Software Foundation, either version 3 of the License, or
 *   (at your option) any later version.
 *
 *   This program is distributed in the hope that it will be useful,
 *   but WITHOUT ANY WARRANTY; without even the implied warranty of
 *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *   GNU General Public License for more details.
 *
 *   You should have received a copy of the GNU General Public License
 *   along with this program.  If not, see <http://www.gnu.org/licenses/>.
 */
defined('_JEXEC') or die('Restricted access'); ?>
<div id="joomdiet_container">
<div id="advise">
    <?php echo JText::_('COM_JOOMDIET_RECIPE_RESULT_ADVISE').': '.($this->customizedamount).'('.JText::_('COM_JOOMDIET_RATIONS').')'; ?>
</div>
<div>
    <span><b><?php echo JText::_('COM_JOOMDIET_RECIPE'); ?>:</b>
    <?php echo ' '.$this->recipe->name; ?></span>
    <?php if ($this->category) { ?>
        <span><b><?php echo JText::_('COM_JOOMDIET_PARENT_CATEGORY'); ?>:</b>
        <?php echo ' '.$this->category->name; ?></span>
    <?php } ?>
</div>
<div>
    <b><?php echo JText::_('COM_JOOMDIET_DESCRIPTION'); ?>:</b>
    <?php echo ' '.$this->recipe->description; ?>
</div>
<div>
    <?php $i = 0; ?>
    <table class="joomdiettable" width="100%">
        <?php $infotype = JRequest::getVar('infotype'); ?>
        <?php if ($infotype == 1) { $total = 0; ?>
            <?php foreach ($this->recipefood as $food) { ?>
                <?php $food_el = $this->food_model->getFood($food->id_food); ?>
                <tr class="row<?php echo $i; ?>">
                    <td width="80%">
                        <?php echo $food_el->name; ?>
                    </td>
                    <td>
                        <?php echo ($food->amount*$this->customizedamount).' '.JText::_('COM_JOOMDIET_GR'); 
                        $total += ($food->amount*$this->customizedamount); ?>
                    </td>
                </tr>
        <?php $i = 1 - $i; } ?>
            <tr class="row0 totalrow">
                <td width="80%">
                    <b><?php echo JText::_('COM_JOOMDIET_TOTAL'); ?></b>
                </td>
                <td>
                    <b><?php echo $total.' '.JText::_('COM_JOOMDIET_GR'); ?></b>
                </td>
            </tr>
        <?php } else {
            $var_result = array();
            foreach ($this->recipefood as $food) { ?>
                <?php
                    $variables = $this->foodvariable_model->getFoodVariables($food->id_food);
                    // total calculation
                    foreach ($variables as $var) {
                        if (!array_key_exists($var->id_variable, $var_result)) {
                            $var_result[$var->id_variable] = 
                                ($var->amount * ($food->amount * $this->customizedamount))/100;
                        } else $var_result[$var->id_variable] += 
                            ($var->amount * ($food->amount * $this->customizedamount))/100;
                    } }
            foreach ($var_result as $key => $variable_result) { 
                $variable = $this->variable_model->getVariable($key); ?>
                <!-- table rendering -->
                <tr class="row<?php echo $i; ?>">
                    <td width="80%">
                        <?php echo $variable->name; ?>
                    </td>
                    <td>
                        <?php echo $variable_result; ?>
                    </td>
                </tr>
            <?php $i = 1 - $i; } ?>
        <?php } ?>
    </table>
</div>

</div>
